package org.wheel.plugins.toolkit.util.sql.ai;


import lombok.Data;
import org.wheel.plugins.toolkit.sql.core.LambdaQueryWrapper;
import org.wheel.plugins.toolkit.sql.core.LambdaUpdateWrapper;
import org.wheel.plugins.toolkit.sql.enums.Dialect;
import org.wheel.plugins.toolkit.sql.enums.SqlModel;

/**
 * 直接跑 main，看各种 UPDATE SQL 输出
 */
public class UpdateSampleMain {

    @Data
    static class User {
        public Long id;
        public String name;
        public Integer age;
    }

    public static void main(String[] args) {
        /* 1. 简单更新 */
        LambdaUpdateWrapper<User> w1 = new LambdaUpdateWrapper<>(User.class)
                .set(User::getName, "Tom")
                .eq(User::getId, 1);
        print(w1, "---- 简单更新 ----");

        /* 2. 混合 SET + 原生表达式 */
        LambdaUpdateWrapper<User> w2 = new LambdaUpdateWrapper<>(User.class)
                .set(User::getName, "Alice")
                .setSql(User::getAge, "age + 1")
                .gt(User::getId, 10);
        print(w2, "---- 混合 SET ----");

        /* 3. 子查询条件 + Mybatis 风格 */
        LambdaUpdateWrapper<User> w3 = new LambdaUpdateWrapper<>(User.class)
                .set(User::getAge, 18)
                .inSub(User::getId,
                        new LambdaQueryWrapper<>(User.class).select(User::getId).eq(User::getAge, 20))
                .dialect(Dialect.MYSQL)
                .sqlModel(SqlModel.MYBATIS);
        print(w3, "---- 子查询 + Mybatis 风格 ----");
    }

    private static void print(LambdaUpdateWrapper<?> w, String title) {
        System.out.println(title);
        System.out.println("SQL   : " + w.getSql());
        System.out.println("Params: " + w.getParamMap());
        System.out.println();
    }
}